﻿function SkillsCatalogManager()
{
    this.SUGGESTIONS_TIMEOUT_MS = 250;  //timeout, before skill suggestions will be loaded (in miliseconds)
    this.SuggestionsTimer = null;

    this.SwitchToYearsOfExperience = function()
    {
        $(".SkillsListLevel").css("display", "none");
        $(".SkillsListExperience").css("display", "block");
        $(".SwitchToSkillLevel").css("display", "inline");
        $(".SwitchToYearsOfExperience").css("display", "none");
    }

    this.SwitchToSkillLevel = function()
    {
        $(".SkillsListExperience").css("display", "none");
        $(".SkillsListLevel").css("display", "block");
        $(".SwitchToYearsOfExperience").css("display", "inline");
        $(".SwitchToSkillLevel").css("display", "none");
    }

    this.PresentSuggestions = function(argSkillNamePart, argSkillType)
    {
        $("#AjaxLoader").css("display", "inline");
        $.post("/Skill/AjaxSuggestions",
            { ajax: true, skillNamePart: argSkillNamePart, skillType: argSkillType },
            function (data) {
                $("#SkillsSuggestion").replaceWith(data);
                $("#AjaxLoader").css("display", "none");
                g_skillsCatalogManager.SetupInteractableSkillsSuggestions();
            }
        );
    }

    this.SetupInteractableSkillsSuggestions = function()
    {
        $("#SkillsSuggestion .SkillHighlightable").removeClass("SkillHighlightable").addClass("SkillInteractable");
        $("#SkillsSuggestion .SkillInteractable").click(
            function()
            {
                var skillId = $(this).find("input").val();
                var skillName = $(this).find(".SkillName").text().trim();
                $("#SkillId").val(skillId);
                $("#Name").val(skillName);
                $("#SkillsSuggestion").html("");
            }
        );
    }

    this.EditEducationEntry = function(element)
    {
        var row = $(element);
        var id = row.find("input").val();
        window.location.href = "/Education/Edit/" + id;
    }

    this.EditCertificate = function(element)
    {
        var row = $(element);
        var id = row.find("input").val();
        window.location.href = "/Certificate/Edit/" + id;
    }

    this.PresentCertificateSuggestions = function(argCertificateNamePart)
    {
        $("#AjaxLoader").css("display", "inline");
        $.post("/Certificate/AjaxSuggestions",
            { ajax: true, certificateNamePart: argCertificateNamePart },
            function (data) {
                $("#CertificatesSuggestion").replaceWith(data);
                $("#AjaxLoader").css("display", "none");
            }
        );
    }

    this.SelectCertificate = function(element)
    {
        var row = $(element);
        var id = row.find("input").val();
        var name = row.find("span").text().trim();
        $("#CertificateId").val(id);
        $("#Name").val(name);
        $("#CertificatesSuggestion").html("");
    }
}

g_skillsCatalogManager = new SkillsCatalogManager();